package ar.unlam.com.cliente;

import java.awt.Font;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.DefaultListModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.BevelBorder;

import model.Notificacion;
import model.Usuario;

public class PantallaPrincipal {
	private JFrame principalFrame;
	private JTextField buscarNombreTextField;
	private JTextField buscarUsuarioTextField;
	private JList<Usuario> listaAmigos;
	private JList<Notificacion> listaNotificaciones;
	private JList<Usuario> listaResultados;
	private DefaultListModel<Usuario> modelListaAmigos;
	private DefaultListModel<Notificacion> modelListaNotificaciones;
	private DefaultListModel<Usuario> modelListaResultados;
	private JButton buscarButton;
	private JLabel resultadosBuscarLabel;
	private JButton logoButton;

	public PantallaPrincipal() {
		initialize();
	}

	private void initialize() {

		principalFrame = new JFrame();
		principalFrame.setBounds(100, 100, 850, 768);
		principalFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		principalFrame.setResizable(false);
		principalFrame.addWindowListener(new WindowListener() {
			
			@Override
			public void windowOpened(WindowEvent arg0) {
			}
			
			@Override
			public void windowIconified(WindowEvent arg0) {
			}
			
			@Override
			public void windowDeiconified(WindowEvent arg0) {
			}
			
			@Override
			public void windowDeactivated(WindowEvent arg0) {
			}
			
			@Override
			public void windowClosing(WindowEvent arg0) {
			}
			
			@Override
			public void windowClosed(WindowEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowActivated(WindowEvent arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		
		JLabel lblNombre = new JLabel("Nombre");
		JLabel lblUsuario = new JLabel("Usuario");
		JLabel notificacionesNewLabel = new JLabel("Notificaciones");
		JLabel amigosNewLabel = new JLabel("Amigos");
		JLabel lblBuscar = new JLabel("Buscar");
		resultadosBuscarLabel = new JLabel("Resultados");

		JPanel busquedaPanel = new JPanel();
		busquedaPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null,
				null, null, null));
		JPanel buscarPanel = new JPanel();
		buscarPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null,
				null, null));
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null,
				null, null));

		buscarNombreTextField = new JTextField();
		buscarNombreTextField.setColumns(10);
		buscarUsuarioTextField = new JTextField();
		buscarUsuarioTextField.setColumns(10);

		buscarButton = new JButton("Buscar");
		buscarButton.setFont(new Font("SansSerif", Font.PLAIN, 14));

		modelListaAmigos = new DefaultListModel<Usuario>();
		modelListaNotificaciones = new DefaultListModel<Notificacion>();
		modelListaResultados = new DefaultListModel<Usuario>();

		listaAmigos = new JList<Usuario>(modelListaAmigos);
		listaNotificaciones = new JList<Notificacion>(modelListaNotificaciones);
		listaResultados = new JList<Usuario>(modelListaResultados);

		JScrollPane scrollAmigos = new JScrollPane(listaAmigos);
		JScrollPane scrollNotificaciones = new JScrollPane(listaNotificaciones);
		JScrollPane scrollResultados = new JScrollPane(listaResultados);

		GroupLayout groupLayout = new GroupLayout(
				principalFrame.getContentPane());
		groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(
				Alignment.LEADING).addGroup(
				groupLayout
						.createSequentialGroup()
						.addContainerGap()
						.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 523,
								GroupLayout.PREFERRED_SIZE)
						.addGap(18)
						.addComponent(buscarPanel, GroupLayout.PREFERRED_SIZE,
								272, GroupLayout.PREFERRED_SIZE)
						.addContainerGap()));
		groupLayout.setVerticalGroup(groupLayout.createParallelGroup(
				Alignment.TRAILING).addGroup(
				Alignment.LEADING,
				groupLayout
						.createSequentialGroup()
						.addContainerGap()
						.addGroup(
								groupLayout
										.createParallelGroup(Alignment.LEADING)
										.addComponent(panel_1,
												Alignment.TRAILING,
												GroupLayout.DEFAULT_SIZE, 655,
												Short.MAX_VALUE)
										.addComponent(buscarPanel,
												Alignment.TRAILING,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE))
						.addContainerGap()));

		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGap(19)
					.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
						.addComponent(amigosNewLabel)
						.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
							.addComponent(notificacionesNewLabel)
							.addComponent(scrollNotificaciones, GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)
							.addComponent(scrollAmigos)))
					.addContainerGap(21, Short.MAX_VALUE))
		);
		gl_panel_1.setVerticalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGap(16)
					.addComponent(amigosNewLabel)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(scrollAmigos, GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
					.addGap(24)
					.addComponent(notificacionesNewLabel)
					.addGap(18)
					.addComponent(scrollNotificaciones, GroupLayout.PREFERRED_SIZE, 245, GroupLayout.PREFERRED_SIZE)
					.addGap(8))
		);
		panel_1.setLayout(gl_panel_1);

		GroupLayout gl_busquedaPanel = new GroupLayout(busquedaPanel);
		gl_busquedaPanel
				.setHorizontalGroup(gl_busquedaPanel
						.createParallelGroup(Alignment.TRAILING)
						.addGroup(
								gl_busquedaPanel
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												gl_busquedaPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addGroup(
																gl_busquedaPanel
																		.createSequentialGroup()
																		.addGroup(
																				gl_busquedaPanel
																						.createParallelGroup(
																								Alignment.LEADING,
																								false)
																						.addComponent(
																								lblUsuario,
																								GroupLayout.DEFAULT_SIZE,
																								GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								lblNombre,
																								GroupLayout.DEFAULT_SIZE,
																								GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE))
																		.addGap(18,
																				24,
																				Short.MAX_VALUE)
																		.addGroup(
																				gl_busquedaPanel
																						.createParallelGroup(
																								Alignment.TRAILING,
																								false)
																						.addComponent(
																								buscarUsuarioTextField)
																						.addComponent(
																								buscarNombreTextField,
																								GroupLayout.DEFAULT_SIZE,
																								142,
																								Short.MAX_VALUE))
																		.addGap(19))
														.addGroup(
																Alignment.TRAILING,
																gl_busquedaPanel
																		.createSequentialGroup()
																		.addComponent(
																				buscarButton,
																				GroupLayout.PREFERRED_SIZE,
																				113,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(58)))));
		gl_busquedaPanel
				.setVerticalGroup(gl_busquedaPanel
						.createParallelGroup(Alignment.LEADING)
						.addGroup(
								gl_busquedaPanel
										.createSequentialGroup()
										.addGap(27)
										.addGroup(
												gl_busquedaPanel
														.createParallelGroup(
																Alignment.BASELINE)
														.addComponent(lblNombre)
														.addComponent(
																buscarNombreTextField,
																GroupLayout.PREFERRED_SIZE,
																19,
																GroupLayout.PREFERRED_SIZE))
										.addGap(18)
										.addGroup(
												gl_busquedaPanel
														.createParallelGroup(
																Alignment.BASELINE)
														.addComponent(
																buscarUsuarioTextField,
																GroupLayout.PREFERRED_SIZE,
																19,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																lblUsuario))
										.addGap(31)
										.addComponent(buscarButton,
												GroupLayout.PREFERRED_SIZE, 39,
												GroupLayout.PREFERRED_SIZE)
										.addGap(21)));
		busquedaPanel.setLayout(gl_busquedaPanel);

		JPanel panelSuperior = new JPanel();
		panelSuperior.setBorder(new BevelBorder(BevelBorder.LOWERED, null,
				null, null, null));

		logoButton = new JButton("");
		logoButton.setIcon(new ImageIcon("source/logo2.png"));
		
		GroupLayout gl_panelSuperior = new GroupLayout(panelSuperior);
		gl_panelSuperior.setHorizontalGroup(
			gl_panelSuperior.createParallelGroup(Alignment.TRAILING)
				.addComponent(logoButton, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
		);
		gl_panelSuperior.setVerticalGroup(
			gl_panelSuperior.createParallelGroup(Alignment.LEADING)
				.addComponent(logoButton, GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
		);
		panelSuperior.setLayout(gl_panelSuperior);
		GroupLayout gl_buscarPanel = new GroupLayout(buscarPanel);
		gl_buscarPanel
				.setHorizontalGroup(gl_buscarPanel
						.createParallelGroup(Alignment.LEADING)
						.addGroup(
								gl_buscarPanel
										.createSequentialGroup()
										.addGroup(
												gl_buscarPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addGroup(
																gl_buscarPanel
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				resultadosBuscarLabel,
																				GroupLayout.PREFERRED_SIZE,
																				117,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_buscarPanel
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				scrollResultados,
																				GroupLayout.PREFERRED_SIZE,
																				234,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_buscarPanel
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				busquedaPanel,
																				GroupLayout.PREFERRED_SIZE,
																				236,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_buscarPanel
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				panelSuperior,
																				GroupLayout.PREFERRED_SIZE,
																				236,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_buscarPanel
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				lblBuscar)))
										.addContainerGap(22, Short.MAX_VALUE)));
		gl_buscarPanel.setVerticalGroup(gl_buscarPanel.createParallelGroup(
				Alignment.TRAILING).addGroup(
				gl_buscarPanel
						.createSequentialGroup()
						.addContainerGap(13, Short.MAX_VALUE)
						.addComponent(panelSuperior,
								GroupLayout.PREFERRED_SIZE, 166,
								GroupLayout.PREFERRED_SIZE)
						.addGap(18)
						.addComponent(lblBuscar)
						.addPreferredGap(ComponentPlacement.UNRELATED)
						.addComponent(busquedaPanel,
								GroupLayout.PREFERRED_SIZE, 178,
								GroupLayout.PREFERRED_SIZE)
						.addGap(25)
						.addComponent(resultadosBuscarLabel)
						.addGap(18)
						.addComponent(scrollResultados,
								GroupLayout.PREFERRED_SIZE, 246,
								GroupLayout.PREFERRED_SIZE).addContainerGap()));

		buscarPanel.setLayout(gl_buscarPanel);
		principalFrame.getContentPane().setLayout(groupLayout);

		principalFrame.setVisible(true);
	}

	public JFrame getPrincipalFrame() {
		return principalFrame;
	}

	public void setPrincipalFrame(JFrame principalFrame) {
		this.principalFrame = principalFrame;
	}

	public JTextField getBuscarNombreTextField() {
		return buscarNombreTextField;
	}

	public void setBuscarNombreTextField(JTextField buscarNombreTextField) {
		this.buscarNombreTextField = buscarNombreTextField;
	}

	public JTextField getBuscarUsuarioTextField() {
		return buscarUsuarioTextField;
	}

	public void setBuscarUsuarioTextField(JTextField buscarUsuarioTextField) {
		this.buscarUsuarioTextField = buscarUsuarioTextField;
	}

	public JButton getBuscarButton() {
		return buscarButton;
	}

	public void setBuscarButton(JButton buscarButton) {
		this.buscarButton = buscarButton;
	}

	public JLabel getResultadosBuscarLabel() {
		return resultadosBuscarLabel;
	}

	public void setResultadosBuscarLabel(JLabel resultadosBuscarLabel) {
		this.resultadosBuscarLabel = resultadosBuscarLabel;
	}

	public void setVisible(boolean flag) {
		this.principalFrame.setVisible(flag);
	}

	public JList<Usuario> getListaAmigos() {
		return listaAmigos;
	}

	public void setListaAmigos(JList<Usuario> listaAmigos) {
		this.listaAmigos = listaAmigos;
	}

	public JList<Notificacion> getListaNotificaciones() {
		return listaNotificaciones;
	}

	public void setListaNotificaciones(JList<Notificacion> listaNotificaciones) {
		this.listaNotificaciones = listaNotificaciones;
	}

	public JList<Usuario> getListaResultados() {
		return listaResultados;
	}

	public void setListaResultados(JList<Usuario> listaResultados) {
		this.listaResultados = listaResultados;
	}

	public DefaultListModel<Usuario> getModelListaAmigos() {
		return modelListaAmigos;
	}

	public void setModelListaAmigos(DefaultListModel<Usuario> modelListaAmigos) {
		this.modelListaAmigos = modelListaAmigos;
	}

	public DefaultListModel<Notificacion> getModelListaNotificaciones() {
		return modelListaNotificaciones;
	}

	public void setModelListaNotificaciones(
			DefaultListModel<Notificacion> modelListaNotificaciones) {
		this.modelListaNotificaciones = modelListaNotificaciones;
	}

	public DefaultListModel<Usuario> getModelListaResultados() {
		return modelListaResultados;
	}

	public void setModelListaResultados(
			DefaultListModel<Usuario> modelListaResultados) {
		this.modelListaResultados = modelListaResultados;
	}

}
